class Tour < ActiveRecord::Base
  attr_accessible :days, :idr_price, :idr_promotion_price, :is_on_promoted, :is_published, :is_recomended, :night, :tour_name_eng, :tour_name_idn, :tour_type_id, :transport_eng, :transport_idn, :usd_price, :usd_promotion_price, :area_id, :primary_picture, :description_eng, :description_idn, :inclusion_eng, :inclusion_idn, :exclusion_eng, :exclusion_idn

  validates :days, :idr_price, :idr_promotion_price, :night, :tour_name_eng, :tour_name_idn, :tour_type_id, :transport_eng, :transport_idn, :usd_price, :usd_promotion_price,  :area_id, :description_eng, :description_idn, presence: true

  mount_uploader :primary_picture, TourUploader

  has_many :tour_days
  has_many :tour_images
  belongs_to :tour_type
  belongs_to :area

  def self.joining_and_search(day_start, day_end, area,price_from ,price_until,tour_type )
    results = Tour

    results = results.where("days" => day_start..day_end ) if !day_start.blank? and !day_end.blank?

    results = results.where("area_id IN (?)", area) if !area.blank?

    results = results.where("tour_type_id IN (?)", tour_type) if !tour_type.blank?

    results
  end

end
